<include file="public/layout" />
<style>
    .hide{
        display:none;
    }
</style>
<body>
<form class="layui-form" action="">
    <input type="hidden" name="id" value="{$info.user_id}" />

    <div class="layui-form-item">
        <label class="layui-form-label">规则</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" name="rule" lay-verify="required" value="{$info.rule}" placeholder="请输入规则" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-text-em">最多32个字</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">关键词</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" name="keywords" value="{$info.keywords}" placeholder="请输入关键词" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-text-em">多个关键字，请以英文逗号隔开(',')</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">回复类型</label>
        <div class="layui-input-inline layui-input-wrap">
            <div class="layui-input-inline" style="width:500px">
                <input type="radio" value="news" title="图文" name="msg_type" <if condition="$info['msg_type'] eq 'news'">checked</if> lay-filter="message_type">
                <input type="radio" value="text" title="文字" name="msg_type" <if condition="$info['msg_type'] eq 'text'">checked</if> lay-filter="message_type">
                <input type="radio" value="image" title="图片" name="msg_type" <if condition="$info['msg_type'] eq 'image'">checked</if> lay-filter="message_type">
                <input type="radio" value="voice" title="音频" name="msg_type" <if condition="$info['msg_type'] eq 'voice'">checked</if> lay-filter="message_type">
                <input type="radio" value="video" title="视频" name="msg_type" <if condition="$info['msg_type'] eq 'video'">checked</if> lay-filter="message_type">
            </div>
        </div>
    </div>
    <div class="layui-form-item" id="message_news" <if condition="$info['msg_type'] eq 'news'">style="display:block;"</if>>
    <label class="layui-form-label" style="width:130px">选择图文：</label>
    <input type="hidden" name="news_content" id="news_content" class="layui-input" value="{$info.news_content}">
    <button style="float:left;" type="button" class="layui-btn layui-btn-primary" onclick="selectnews()">选择图文</button>
    <div id="news_contentPreview" style="float:left;padding-top:10px;margin-left:95px;clear:both;">

    </div>
    </div>
    <div class="layui-form-item hide" id="message_text" <if condition="$info['msg_type'] eq 'text'">style="display:block;"</if>>
    <label class="layui-form-label" style="width:130px">文字内容：</label>
    <div class="layui-input-inline" style="width:500px">
        <textarea id="text_content" name="text_content" style="width:474px;height:140px" class="layui-textarea">{$info.text_content}</textarea>

    </div>
    </div>
    <div class="layui-form-item hide" id="message_image" <if condition="$info['msg_type'] eq 'image'">style="display:block;"</if>>
    <label class="layui-form-label" style="width:130px">选择图片：</label>
    <input type="hidden" name="image_content" id="image_content" class="layui-input" value="{$info.image_content}">
    <button style="float:left;" type="button" class="layui-btn layui-btn-primary" upload-input="image_content" upload-preview="image_contentPreview" onclick="uploader(this,false,{'browser':'active','wximage':''})">上传图片</button>
    <div class="layui-form-mid layui-word-aux" style="margin-left:10px;">不大于2M</div>
    <div id="image_contentPreview" style="float:left;padding-top:10px;margin-left:160px;clear: both;">
        <div class="layui-imgbox" style="width:100px;"><div class="layui-imgbox-img"><img src="{$info.image_content}"/></div></div>
    </div>
    </div>
    <div class="layui-form-item hide" id="message_voice" <if condition="$info['msg_type'] eq 'voice'">style="display:block;"</if>>
    <label class="layui-form-label" style="width:130px">选择音频：</label>
    <input type="hidden" name="voice_content" value="{$info.voice_content}" id="voice_content"/>
    <button style="float:left;" type="button" class="layui-btn layui-btn-primary" upload-input="voice_content" upload-preview="voice_contentPreview" onclick="uploader(this,false,{'browser':'active','wxvoice':''})">上传音频</button>
    <div id="voice_contentPreview" class="layui-form-mid" style="margin-left:20px;"></div>
    <div class="layui-form-mid layui-word-aux" style="margin-left:10px;">请上传mp3格式的音频，不大于2M</div>
    <script>
        function delaudio(){
            $('#voice_contentPreview').html('');
            $('#voice_content').val('');
        }
    </script>
    </div>
    <div id="message_video" class="hide" <if condition="$info['msg_type'] eq 'video'">style="display:block;"</if>>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:130px">选择视频：</label>
        <input type="hidden" name="video_content" value="{$info.video_content}" id="video_content"/>
        <button style="float:left;" type="button" class="layui-btn layui-btn-primary" upload-input="video_content" upload-preview="video_contentPreview" onclick="uploader(this,false,{'browser':'active','wxvideo':''})">上传视频</button>
        <div id="video_contentPreview" class="layui-form-mid" style="margin-left:20px;"></div>
        <div class="layui-form-mid layui-word-aux" style="margin-left:10px;">请上传mp4格式的视频，不大于10M</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:130px">视频标题</label>
        <div class="layui-input-inline" style="width:300px">
            <input type="text" value="{$info.video_title}" name="video_title" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"style="width:130px">视频描述</label>
        <div class="layui-input-inline" style="width:300px">
            <input type="text" value="{$info.video_introduction}" name="video_introduction" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="subbtn">确认</button>
        </div>
    </div>
</form>
<load href="__ROOT__/public/plugins/Ueditor/ueditor.config.js"/>
<load href="__ROOT__/public/plugins/Ueditor/ueditor.all.min.js"/>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script>
    var url="{:url('Ueditor/index',array('savePath'=>'weixin_mp_news'))}";
    var ue = UE.getEditor('content',{
        serverUrl :url,
        zIndex: 999,
        initialFrameWidth: "100%", //初化宽度
        initialFrameHeight: 300, //初化高度
        focus: false, //初始化时，是否让编辑器获得焦点true或false
        maximumWords: 99999, removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign',//允许的最大字符数 'fullscreen',
        pasteplain:false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
        autoHeightEnabled: true
    });
    layui.use(['form', 'laydate', 'util'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;

        // 自定义验证规则
        form.verify({
            pass: [
                /^[\S]{6,12}$/,
                '密码必须6到12位，且不能出现空格'
            ]
        });

        // 指定开关事件
        // form.on('switch(switchTest)', function(data){
        //     layer.msg('开关 checked：'+ (this.checked ? 'true' : 'false'), {
        //         offset: '6px'
        //     });
        //     layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是 ON|OFF', data.othis)
        // });

        // 提交事件
        form.on('submit(subbtn)', function(data){
            var index = layer.load();
            layer.close(index);

            var field = data.field; // 获取表单字段值
            $.ajax({
                type: "POST",
                url: "{:url('Wechat/add_auto_reply')}",
                data: field,
                success: function(res){
                    console.log(res);
                    if(res.status){
                        layer.msg(res.msg, {icon: 1, time: 1000}, function () {
                            location.href = "{:U('Wechat/auto_reply', ['tab' => 'news'])}";
                        });
                    }else{
                        layer.msg(res.msg);
                    }
                }
            });
            return false; // 阻止默认 form 跳转
        });

        // 日期
        laydate.render({
            elem: '#date'
        });
    });
    layui.form.on('radio(message_type)', function(data){
        var elem = data.elem; // 获得 radio 原始 DOM 对象
        var checked = elem.checked; // 获得 radio 选中状态
        var value = elem.value; // 获得 radio 值
        if(value=='news'){
            $('#message_news').show();
            $('#message_text').hide();
            $('#message_image').hide();
            $('#message_voice').hide();
            $('#message_video').hide();
        }else if(value=='text'){
            $('#message_text').show();
            $('#message_news').hide();
            $('#message_image').hide();
            $('#message_voice').hide();
            $('#message_video').hide();
        }else if(value=='image'){
            $('#message_image').show();
            $('#message_text').hide();
            $('#message_news').hide();
            $('#message_voice').hide();
            $('#message_video').hide();
        }else if(value=='voice'){
            $('#message_voice').show();
            $('#message_image').hide();
            $('#message_text').hide();
            $('#message_news').hide();
            $('#message_video').hide();
        }else if(value=='video'){
            $('#message_video').show();
            $('#message_voice').hide();
            $('#message_image').hide();
            $('#message_text').hide();
            $('#message_news').hide();
        }
    });
    function img_call_back(fileurl_tmp)
    {
        $("#imagetext").val(fileurl_tmp);
        $("#img_a").attr('href', fileurl_tmp);
        $("#img_i").attr('onmouseover', "layer.tips('<img src="+fileurl_tmp+">',this,{tips: [1, '#fff']});");
    }
</script>
</body>
</html>